use ATE 
Go


IF OBJECT_ID ( 'Vendor_Insert', 'P') IS NOT NULL 
    DROP PROCEDURE Vendor_Insert;
GO
CREATE PROCEDURE Vendor_Insert
    @VendorID nvarchar(50),
	@VendorName nvarchar(50) =null	
AS    
    if(Exists(select * from Vendor where VendorID=@VendorID))    
		begin
			RAISERROR ('The VendorID is already exist',16,1)
			RETURN
		end
	insert into Vendor(VendorID,VendorName) values(@VendorID,@VendorName)
GO


IF OBJECT_ID ( 'Vendor_Delete', 'P') IS NOT NULL 
    DROP PROCEDURE Vendor_Delete;
GO
CREATE PROCEDURE Vendor_Delete
    @VendorID nvarchar(50)	
AS    
    if(not Exists(select * from Vendor where VendorID=@VendorID))    
		begin
			RAISERROR ('The VendorID is not exist',16,1)
			RETURN
		end
	delete from Vendor where VendorID=@VendorID
GO





IF OBJECT_ID ( 'Vendor_select', 'P' ) IS NOT NULL 
    DROP PROCEDURE Vendor_select;
GO
CREATE PROCEDURE Vendor_select
AS    
    SET NOCOUNT ON;
    select VendorID,VendorName
	from Vendor	
	order by VendorID 
GO


IF OBJECT_ID ( 'Vendor_selectbyID', 'P' ) IS NOT NULL 
    DROP PROCEDURE Vendor_selectbyID;
GO
CREATE PROCEDURE Vendor_selectbyID
	@VendorID nvarchar(50)
AS    
    SET NOCOUNT ON;
    select VendorID,VendorName
	from Vendor
	where VendorID=@VendorID;	
GO



















